; DerbyRam - In memory 1939-2007
; a simple demo to say goodbye to a nice
; person which everyone in the C64 scene
; will miss: Derbyshire Ram
; 2007.06.08 iAN CooG/HokutoForce
;---------------------------------------

init = $1000
play = $1003
RAST1 = $0b
RAST2 = $fa

scr = $4000
sprptr = scr+$3f8
col = $d800

    *=$0801
    word eop
    word 7102
    byte $9e,"2061",0
eop word 0

    lda #$00
    sta $d011
    sta $d020
    sta $d021
    sei
    lda #<irq1
    sta $0314
    lda #>irq1
    sta $0315
    lda #$7f
    sta $dc0d
    sta $dd0d
    lda $dc0d
    lda #$01
    sta $d01a
    sta $d019

    lda #$0b
    sta $d011
    lda #RAST1
    sta $d012
    lda #0
    sta counter1
    sta counter2
    sta patch1+1
    tax
    tay
    jsr $1000
    cli
patch1
    lda #00
    beq patch1
    jsr showkoala
    lda #$0c
    sta $D025
    lda #$00
    sta $D026
    lda #$0f
    ldy #$07
setspcol
    sta $D027,y
    dey
    bpl setspcol
    ;LDY #$ff
    ;STY $D017
    STY $D01c
    STY $D015    ; all sprites active

    lda #%11000000  ; sprite 6-7 on right side, after 256th pixel
    sta $d010
    lda #$20        ; now position them at step of 40 pixels
    ldx #$00
setspr1
    sta $d000,x
    pha
    lda #$11
    inx
    sta $d000,x
    pla
    clc
    adc #$28
    inx
    cpx #$10
    bne setspr1
    ldx #$07
setspr2
    lda sprorder,x
    sta sprptr,x
    dex
    bpl setspr2

    jmp *
;---------------------------------------
irq1
    asl $d019
    jsr $1003
    inc counter1
    lda counter1
    cmp #$9b
    bne exitirq1
    lda #0
    sta counter1
    lda counter3
    and #$0f
    tax
    lda fader,x
    sta $d020
    inc counter3
    cpx #$04
    bne exitirq1
    stx patch1+1
    lda #<irq2
    sta $0314
    lda #>irq2
    sta $0315
    lda #$0b
    sta $d011
    lda #RAST1
    sta $d012

exitirq1
    jmp $ea81
;---------------------------------------
irq2
    asl $d019
    jsr $1003

    lda counter1
    and #$03
    sta counter1
    bne noincc
    lda counter3
    and #$1f
    tax
    lda fader,x
    sta $d020
    lda fader2,x
    sta $d026
    inc counter3
noincc
    inc counter1
    lda #<irq3
    sta $0314
    lda #>irq3
    sta $0315
    lda #$3b
    sta $d011
    lda #RAST2
    sta $d012
exitirq2
    jmp $ea81
;---------------------------------------
irq3
    LDA #$33
    STA $D011

    ldy #11   ;2
ldel1
    nop       ;2
    dey       ;2
    bne ldel1 ;2 = 6 * 11  + 2 = 68
    bit $24   ;3 = 71

    LDA #$3B
    STA $D011

    asl $D019

    lda #<irq2
    sta $0314
    lda #>irq2
    sta $0315
    lda #$3b
    sta $d011
    lda #RAST1
    sta $d012
exitirq3
    jmp $ea81
;---------------------------------------

counter1
    byte 0
counter2
    byte 0
counter3
    byte 0

fader
    byte $0b,$0c,$0f,$01
    byte $01,$01,$01,$01
    byte $01,$01,$01,$01
    byte $01,$01,$01,$01
    byte $01,$01,$01,$01
    byte $01,$01,$01,$01
    byte $01,$01,$01,$01
    byte $0f,$0c,$0b,$00
fader2
    byte $00,$00,$00,$00
    byte $00,$00,$00,$00
    byte $0b,$0c,$0f,$01
    byte $0f,$0c,$0b,$00
    byte $00,$00,$00,$00
    byte $00,$00,$00,$00
    byte $00,$00,$00,$00
    byte $00,$00,$00,$00
;---------------------------------------


    *=$1000
    incprg Missing_Past.prg


    *=$4800
showkoala

        ldx #$00
copy    lda scrpos     ,x
        sta scr        ,x
        lda scrpos+$100,x
        sta scr   +$100,x
        lda scrpos+$200,x
        sta scr   +$200,x
        lda scrpos+$300,x
        sta scr   +$300,x
        lda colpos     ,x
        sta col        ,x
        lda colpos+$100,x
        sta col   +$100,x
        lda colpos+$200,x
        sta col   +$200,x
        lda colpos+$300,x
        sta col   +$300,x
        dex
        bne copy
        lda colpos+1000
        sta $d021
        lda #$08 ; scr=$4000 bmp=$6000
        sta $d018
        lda #$02
        sta $dd00
        lda #$d8
        sta $d016

        lda #$00
        sta $7fff

        lda $d011
        bmi *-3
        lda #$3b
        sta $d011
        rts
;---------------------------------------
    *=$5c00
spriteletter ;DERBYAM, reuse R
    incprg derbyam.spr
sprorder
    byte [spriteletter/$40]+0
    byte [spriteletter/$40]+1
    byte [spriteletter/$40]+2
    byte [spriteletter/$40]+3
    byte [spriteletter/$40]+4
    byte [spriteletter/$40]+2
    byte [spriteletter/$40]+5
    byte [spriteletter/$40]+6
;---------------------------------------
    *=$6000
koala
scrpos = koala+8000
colpos = koala+9000
    incprg derbyram_inmemory02.kla
;---------------------------------------
